﻿<Window x:Class="Netfraction.FileListWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Netfraction"
    Title="FileList" Height="608" Width="988">
    <Window.Resources>
        <local:XElementConverter x:Key="ElemConverter"/>
        <local:XFileElementConverter x:Key="FileConverter"/>
        <local:BytesConverter x:Key="BytesConverter"/>
        <local:HeaderToImageConverter x:Key="HeaderToImageConverter"/>
        <local:PathToImageConverter x:Key="PathToImageConverter"/>
        <local:PathFileTypeConverter x:Key="PathFileTypeConverter"/>
        <local:TreeViewSortConverter x:Key="TreeViewSortConverter"/>
        
        <HierarchicalDataTemplate DataType="Directory" ItemsSource="{Binding Converter={StaticResource ElemConverter}}">
            <StackPanel Orientation="Horizontal">
                <Image Name="img"  Width="20" Height="20" Stretch="Fill"
                    Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                    AncestorType={x:Type TreeViewItem}},
                    Path=IsExpanded,
                    Converter={x:Static local:HeaderToImageConverter.Instance}}" />
                <TextBlock Text="{Binding Path=Attribute[Name].Value}" />
                </StackPanel>
        </HierarchicalDataTemplate>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200*" />
            <ColumnDefinition Width="Auto" MinWidth="5" />
            <ColumnDefinition Width="560*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" MinHeight="5" />
            <RowDefinition Height="100" />
        </Grid.RowDefinitions>
        <GridSplitter Grid.Column="1"
              HorizontalAlignment="Center"
              VerticalAlignment="Stretch"
              ShowsPreview="True"
              Width="5"
              />
        <GridSplitter Grid.Row="1" Grid.ColumnSpan="3"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Center"
              ShowsPreview="True"
              Height="5"
              />
        <TreeView Grid.Column="0" Grid.Row="0" Name="folderTreeView" ItemsSource="{Binding Path=Root.Elements}" SelectedItemChanged="folderTreeView_SelectedItemChanged" />
        <ListView Grid.Column="2" Grid.Row="0" Name="fileListView" ContextMenuOpening="filesContextMenu_ContextMenuOpening">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="400" Header="File Name">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Name="img2"  Width="16" Height="16" Stretch="Fill" Margin="2,0,2,0"
                                        Source="{Binding 
                                        Path=Attribute[Name].Value,
                                        Converter={x:Static local:PathToImageConverter.Instance}}" />
                                    <TextBlock Text="{Binding Path=Attribute[Name].Value}" />
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="200" Header="Type" DisplayMemberBinding="{Binding Path=Attribute[Name].Value, Converter={StaticResource PathFileTypeConverter}}" />
                    <GridViewColumn Width="80" Header="Size" DisplayMemberBinding="{Binding Path=Attribute[Size].Value, Converter={StaticResource BytesConverter}}" />
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu Name="filesContextMenu" StaysOpen="False">
                    <MenuItem Name="downloadFileMenuItem" Header="Download" Click="downloadFileMenuItem_Click"/>
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
        
        <ListView Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" Name="downloadListView" />
    </Grid>
</Window>
